{include file="admin@public/header"/}
<link rel="stylesheet" href="/public/static/admin/easyui/layui-v2.6.8/css/layui.css">

<style type="text/css">
	.mod-search {
		position: relative;
	}

	#custom {
		position: absolute;
		top: 0;
		right: 0;
	}

	#manager li {
		margin: 8px 0;
	}

	.url-box {
		padding: 5px;
		line-height: 26px;
		cursor: pointer;
	}

	.url-box a {
		margin-right: 5px;
	}

	#manager .ui-label {
		/* width: 204px; */
		display: inline-block;
		line-height: 18px;
		font-size: 14px;
		text-align: center;
	}

	#manager .ui-label-warning:hover {
		background-color: #FFBA5A;
	}

	.no-query {
		border: none;
	}

	.ul-inline li {
		margin-right: 20px;
	}

	#tipsBox p {
		line-height: 24px;
	}

	td.srcOrderNo {
		text-decoration: underline;
		cursor: pointer;
	}
	.ul-inline li{
		padding: 2px 0;
	}
	.ui-droplist-wrap .droplist .list-item:hover{
		background-color: #faffad;
	}
	.layui-form-checkbox[lay-skin=primary] i {
		padding: 0;
	}
	.layui-form-checked[lay-skin=primary] i {
		border-color: #5dc5e7;
		background-color: #5dc5e7;
		color: #fff;
		padding: 0;
	}

	.layui-form-checkbox[lay-skin=primary]:hover i {
		border-color: #5dc5e7;
	}
	.shadow.opera-log-box::before,
	.shadow.opera-log-box::after {
		border: solid transparent;
		content: ' ';
		height: 0;
		bottom: 100%;
		position: absolute;
		width: 0;
	}

	.shadow.opera-log-box:after {
		border-width: 8px;
		border-bottom-color: #FFEED4;
		right: 26px;
	}

	.shadow.opera-log-box:before {
		border-width: 10px;
		border-bottom-color: #E1B77E;
		right: 24px;
	}
	.mod-choose-input{position: relative;}
	.ui-input{width: 150px;}
</style>

<div class="bill-ser-top">
	<ul class="ul-inline cf layui-form">

		<!-- 选择仓库 -->
		{include file="admin@select/store"/}

		<!-- 选择商品类别 -->
		{include file="admin@select/goods_category"/}

		<!-- 选择商品 -->
		{include file="admin@select/goods"/}

		<li id="chkField" style="padding-top: 8px;">
			<input type="checkbox" name="box" id="chkFieldInput" lay-skin="primary" title="只显示［建议采购量］大于0的商品" checked="">
		</li>
		<li><a class="mrb ui-btn ui-btn-search" id="search">查询</a></li>

		<li id="tips" style="float: right; padding-right: 20px">
			<img src="/public/static/admin/css/img/pd-tips.png" style="width: 20px; height: 20px; padding-left: 20px">
			<div id="tipsBox" class="shadow opera-log-box " style="position: absolute; z-index: 999; display: none;">
				<p style="white-space: nowrap;">销售在订量：统计该商品所有关联的已生效销货订单的订购数量；</p>
				<p class="wdOrderQty" style="display: none;">网店订购量：统计该商品所有关联的已付款或货到付款网上订单的订购数量；</p>
				<p>采购在订量：统计该商品所有关联的已生效采购订单的订购数量；</p>
				<p>最低库存：取商品管理中设置的库存预警值（总仓预警、分仓预警或按属性预警）。</p>

			</div>
		</li>
	</ul>
</div>

<!-- 下拉树选择（商品类别） -->
{include file="admin@popup/goods_category"/}


<div class="wrapper btc">
	<div class="bill-ser-botm">
		<div class="cf">
			<div class="ui-config-box">
			  <span id="config" class="ui-config"><a href="#" class="ui-icon-config-new"></a>列设置</span>
			</div>
			<div class="fr">
			  <a class="ui-btn-bill ui-btn-add " id="formula">计算公式</a>
			  <a class="ui-btn-bill ui-btn-add ml10" id="toPo"  onclick="addFun()">生成购货订单</a>
			  <a href="#" class="ui-btn-bill ui-btn-hl ml10" id="export">导出</a>
			</div>
		</div>
	</div>
	<div class="grid-wrap">
		<table id="grid">
		</table>
		<div id="page"></div>
	</div>
</div>




<script type="text/javascript" src="/public/static/admin/easyui/jeasyui/jquery.easyui.min.js"></script>

<script type="text/javascript">
	//$(function(){
	$(document).ready(function () {
		var goods_id = $('#goods_id').val();//选择商品
		var goods_category_id = $('#goods_category_id').val();//选择商品类别
		var store_id = $('#store_id').val();//选择仓库

		//alert("1111");
		$("#grid").jqGrid({
			url: '/scm/autoremedy/index.html?ajax=100&goods_id='+goods_id+'&goods_category_id='+goods_category_id+'&store_id='+store_id+'&jycgl=1&search=1',
			datatype: "json",//数据来源，本地数据（local，json,jsonp,xml等）
			height: '90%',//高度，表格高度。可为数值、百分比或'auto'
			//width: Public.setGrid().w,
			//height: Public.setGrid().h,
			colNames: [ "商品", "单位", "销售在订量", "网店订购量", "库存余额", "采购在订量", "最低库存", "建议采购量",'good_id'],
			colModel: [
				{ name: 'name', width: 200 ,lable:"商品"},
				{ name: 'unit_name' , width: 150 ,lable:"单位"},
				{ name: 'sales_num', width: 120 ,lable:"销售在订量" },
				{ name: 'online_sales_num', width: 120 ,lable:"网店订购量" },
				{ name: 'ck', width: 120 ,lable:"库存余额" },
				{ name: 'cg_num', width: 120 ,lable:"采购在订量" },
				{ name: 'low_num', width: 120 ,lable:"最低库存" },
				{ name: 'jy_num', width: 120 ,lable:"建议采购量" },
				{ name: 'good_id', width: 100 ,hidden:true}
			
			],
			rowNum: 10,
			rowList: [10, 20, 30],
			sortname: 'id',
			sortorder: "desc",
			pagerpos: "left",//分页位置
			multiselect:true,//自带多选
			pgbuttons: true,//翻页按钮
			pagination: true,
			altRows: !0,
			gridview: !0,
			shrinkToFit: !1,
			cellLayout: 8,
			autowidth: !0,
			pager: "#page",
			viewrecords: !0,
			cmTemplate: {
				sortable: !1,
				title: !1
			},
			
			loadError: function (t, e, i) {
				parent.Public.tips({
					type: 1,
					content: "操作失败了哦，请检查您的网络链接！"
				})
			}
		});
	});

</script>
<script type="text/javascript">
	$(document).ready(function () {
			// 导出按钮
			$("#export").click(function () {
				grid_search_list(1);//0 查询 1 导出
			});

			// 点击查询按钮
			$("#search").click(function () {
				grid_search_list(0);//0 查询 1 导出
			});
	 });
		//$action_type 0 查询 1 导出
	function grid_search_list($action_type){
		    // 判断是否勾选建议采购量大于0
            var jycgl=0;
            if ($("#chkFieldInput").get(0).checked) {
              	jycgl=1;
            }else{
               	jycgl=0;
            }

		
			var goods_id = $('#goods_id').val();//选择商品
			var goods_category_id = $('#goods_category_id').val();//选择商品类别
			var store_id = $('#store_id').val();//选择仓库


			if ($action_type==0) {
				var param={ 'ajax': '100',  'goods_id': goods_id,'goods_category_id':goods_category_id,'store_id':store_id,'jycgl':jycgl,'search':1};  //发送数据
			}else if($action_type==1){
				var param={ 'is_export':1,'ajax': '100',  'goods_id': goods_id,'goods_category_id':goods_category_id,'store_id':store_id,'jycgl':jycgl,'search':1};
				var export_param='';
				for(let key  in param){
					export_param+=key+'='+ param[key]+'&';
				}
				export_param = export_param.substr(0, export_param.length - 1);  
				//console.log(export_param);
				window.location.href="index.html?"+export_param;
				return false;
			}
			//此处可以添加对查询数据的合法验证 
			$("#grid").jqGrid('setGridParam', {
				datatype: 'json',
				postData: param, //发送数据 
				page: 1
			}).trigger("reloadGrid"); //重新载入 
	}
	
</script>
<script type="text/javascript">
		// 生成订单
	function addFun(){
		var ids=$("#grid").jqGrid('getGridParam','selarrrow');
		//var rowData = $('#grid').jqGrid('getRowData',row);
		var selectRowData=[];
	    for (var k = 0; k < ids.length; k++) {
	        var rowData=$("#grid").jqGrid('getRowData', ids[k]); 
	        selectRowData.push(rowData);
	    }

	    if (0 == selectRowData.length) {
	      layer.msg("请先选择单据！");
	      return false;
	    }
        var selectRow = JSON.stringify(selectRowData);      
        parent.tab.addTabItem({
            tabid: "purchaseinvSa",
            text: "购货订单",
            url:"/scm/purchase/edit.html?xxdd_ids="+ids+"&xxdd_RowData="+selectRow+"&is_znbh=1",
        })
		console.log(ids);
	}

</script>

{include file="admin@public/footer"/}